package com.tgy.leetcode;

import java.util.Stack;

/**
 * https://leetcode-cn.com/problems/132-pattern/
 */

public class _456_132模式 {

    public static boolean  find132pattern(int[] nums) {

        Stack<Integer> stack = new Stack<>();
        boolean flag = false;
        for (int num : nums) {

            flag = false;
            while (!stack.isEmpty() && stack.peek() >= num) {

                Integer val = stack.pop();

                if (val > num) {
                    flag = true;
                }
            }

            if (!stack.isEmpty() && flag) {

                return true;
            }

            stack.push(num);
        }

        return false;
    }

    public static void main(String[] args) {

//        int[] nums = {-2,1,-2};
        int[] nums = {-1,3,2,0};
        boolean res = find132pattern(nums);
        System.out.println(res);

    }
}
